base_dir=$(
  cd "$(dirname "$0")"
  pwd
)
function logger() {
front=$1
back=$2
content=$3
echo -e "\e["$back";"$front"m"$content"\e[0m"
}


export PATH=$PATH:/home/debi/go/bin
go env -w CGO_ENABLED=0
go env -w GOOS=linux
go env -w GOARCH=amd64
export NODE_OPTIONS=--max_old_space_size=4096

logger 31 40 "----begin----"
targetIp=""

projectBase=$base_dir
mainGoPath=$projectBase/back/web/cmd/main.go
targetPath=$projectBase/back/web/cmd/main

read -p "front build? [0/1] " type
case $type in
0)   ;;
1)
  rm -rf $projectBase/back/web/static/assets/
  rm -rf $projectBase/back/web/static/index.html
  rm -rf $projectBase/front/components.d.ts
  cd $projectBase/front
  npm i
  npm run build
;;
esac

#go env -w GOPRIVATE="*" && garble -literals build .
#go build -a debi-installsuffix cgo -ldflags "-s " -o /home/debi/IdeaProjects/1panel/cmd/server/1panel main.go
cd $projectBase/back/web/cmd

read -p "build? [0/1] " type
case $type in
1)
go build -o $targetPath $mainGoPath ;;
esac

read -p "upx? [0/1] " type
case $type in
1) upx $ targetPath  ;;
esac

for i in {1..3} ; do
logger 33 40 "Loop  $i"

read -p "scp target? [number] " type
case $type in
0) exit ;;
1)
   #   remote
  targetIp=192.168.8.20
  password="666888"
;;
esac

logger 33 40 "Current $targetIp"
sshpass -p  $password  scp $ targetPath root@$targetIp:/home/panel/panel_main_new && logger 33 41 "scp successful $targetIp" &
done


#sudo date --set="$(ssh root@67.21.86.154 'date -u')"
#scp $ targetPath root@67.21.86.154:/root/
#scp conf/app_remote.yaml root@67.21.86.154:/opt/1panel/conf/app.yaml
